#pragma once
#include"BRTree.h"

namespace xhy
{
	template<class K, class V>
	struct select1st
	{
		const K& operator()(const pair<K, V>& kv) { return kv.first; }
	};

	template<class K, class V>
	class map
	{
		typedef BRTree<const K, pair<const K, V>, select1st<K, V>> BRTree;
	public:
		typedef typename BRTree::Iterator iterator;
		typedef typename BRTree::Const_Iterator const_iterator;
	public:
		iterator begin() { return _t.Begin(); }
		const_iterator begin() const { return _t.Begin(); }
		iterator end() { return _t.End(); }
		const_iterator end() const { return _t.End(); }

		pair<iterator, bool> insert(const pair<K, V>& kv) { return _t.Insert(kv); }
		V& operator[](const K& key)
		{
			pair<iterator, bool> Pair = insert({ key , V()});
			return (Pair.first)->second;
		}

	private:
		BRTree _t;
	};
}